import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class WindowClosing {

	public static void main(String[] args) {
		Frame frm = new Frame("Frame with Controls");
		frm.setLayout(new FlowLayout());

		Label lbl = new Label("Here is a label.");
		frm.add(lbl);

		Button btn = new Button("Click Me");
		frm.add(btn);

		WindowEventHandlers handler = new WindowEventHandlers();
		frm.addWindowListener(new WindowAdapter()
			{
				@Override
				public void windowClosed(WindowEvent e) {
					Window w = e.getWindow();
					w.dispose();
				}
			 
			}
		);
		btn.addMouseListener(handler);

		frm.setBounds(100, 100, 250, 100);
		frm.setVisible(true);
	}
}
